import pandas as pd
import numpy as np

s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
print(s)

d = {
    'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
    'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
    '自定义': '自定义'
}
df = pd.DataFrame(d)

print(df)

# 选取
# 按行的索引: 行号、索引值
print("====", "按行的索引:行号" + "====")
print(df.iloc[0])
print("====", "按行的索引:索引值" + "====")
print(df.loc['d'])

# 按列的索引
print("====", "按列的索引:列名称-单列" + "====")
print(df['two'])
print("====", "按列的索引:列名称-多列" + "====")
print(df[['two', 'one']])

# 行列同时选择进行筛选
print("====", "行列同时选择进行筛选" + "====")
print(df['two'].loc['d'])
print(df[['two', 'one']].loc['d'])

# 模糊查询: 大于0的所有数据
print("====", "模糊查询: 大于2的所有数据" + "====")
print(df[(df['one'] > 2) & (df['two'] > 2)])

# 精确查询
print("====", "模糊查询: 等于2的所有数据" + "====")
print(df[df['one'] != 2])
print(df[(df['one'] == 2) & (df['two'] == 2)])

# 数据分析的流程
